﻿<UserControl x:Class="JsdEditor.StructureView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:local="clr-namespace:JsdEditor"
             mc:Ignorable="d" 
             d:DesignHeight="600" d:DesignWidth="800">
    <UserControl.Resources>
        <local:BoolToVisibilityConverter x:Key="BoolToVisibilityConverter" />
    </UserControl.Resources>
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition />
            <ColumnDefinition Width="Auto" />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="1*" />
            <RowDefinition Height="2*" />
        </Grid.RowDefinitions>
        <DockPanel MaxWidth="280" Margin="5" x:Name="dpTiles" Visibility="{Binding IsContainsStructureData}">
            <Label DockPanel.Dock="Top" Content="Structure Tiles" FontSize="14" FontWeight="Medium" />
            <StackPanel DockPanel.Dock="Top" Orientation="Horizontal">
                <Button Content="Add Tile" Command="{Binding AddTileCommand}" CommandParameter="{Binding}" />
                <Button Content="Delete Tile" Command="{Binding RemoveTileCommand}" CommandParameter="{Binding}" />
                <Button Content="Copy Tile" Command="{Binding CopyTileCommand}" CommandParameter="{Binding}" />
                <Button Command="{Binding RotateTileCommand}" CommandParameter="{Binding}" ToolTip="Copy and rotate 90 degrees clockwise">
                    <Path Stroke="Black" StrokeThickness="3" Data="{StaticResource ClockwiseRotateArrow}" />
                </Button>
                <Button Command="{Binding AntiRotateTileCommand}" CommandParameter="{Binding}" ToolTip="Copy and rotate 90 degrees counterclockwise">
                    <Path Stroke="Black" StrokeThickness="3" Data="{StaticResource ClockwiseRotateArrow}" RenderTransformOrigin="0.5 0.5">
                        <Path.RenderTransform>
                            <MatrixTransform Matrix="-1, 0, 0, 1, 0, 0" />
                        </Path.RenderTransform>
                    </Path>
                </Button>
            </StackPanel>
            <DataGrid x:Name="dgTiles"
                  ItemsSource="{Binding Tiles}" 
                  SelectedCellsChanged="DataGrid_SelectedCellsChanged"
                  AutoGenerateColumns="False">
                <DataGrid.Columns>
                    <DataGridTextColumn Width="64"
                    Binding="{Binding Path=XPosRelToBase}"
                    Header="X Position Relativity To Base"
                    HeaderStyle="{StaticResource ColumnHeaderStyle}" />
                    <DataGridTextColumn Width="64"
                    Binding="{Binding Path=YPosRelToBase}"
                    Header="Y Position Relativity To Base"
                    HeaderStyle="{StaticResource ColumnHeaderStyle}" />
                    <DataGridCheckBoxColumn Width="64"
                    Binding="{Binding Path=TileIsPassable}"
                    Header="Is Passable"
                    HeaderStyle="{StaticResource ColumnHeaderStyle}" />
                    <DataGridCheckBoxColumn Width="64"
                    Binding="{Binding Path=TileIsOnRoof}"
                    Header="Is on Roof"
                    HeaderStyle="{StaticResource ColumnHeaderStyle}" />
                </DataGrid.Columns>
                <DataGrid.ContextMenu>
                    <ContextMenu>
                        <MenuItem Header="Set initial tile" Command="{Binding SetInitialTileCommand}" CommandParameter="{Binding}" />
                    </ContextMenu>
                </DataGrid.ContextMenu>
            </DataGrid>
        </DockPanel>
        <DockPanel Grid.Column="1" Margin="5" Visibility="{Binding IsNotContainsStructureData, 
            Converter={StaticResource BoolToVisibilityConverter}}">
            <Label  DockPanel.Dock="Top" Content="Tile Location Data" FontSize="14" FontWeight="Medium" />
            <DataGrid x:Name="dgTileLocData"
                  ItemsSource="{Binding TileLocData}" 
                  SelectedItem="{Binding SelectedTileLocData}"
                  AutoGenerateColumns="False">
                <DataGrid.Columns>
                    <DataGridTextColumn Width="64"
                    Binding="{Binding Path=X}"
                    Header="X Position Relativity To Base"
                    HeaderStyle="{StaticResource ColumnHeaderStyle}" />
                    <DataGridTextColumn Width="64"
                    Binding="{Binding Path=Y}"
                    Header="Y Position Relativity To Base"
                    HeaderStyle="{StaticResource ColumnHeaderStyle}" />
                </DataGrid.Columns>
            </DataGrid>
        </DockPanel>
        <Grid Grid.Column="2">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition />
                <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>
            <Slider x:Name="sImageHorPos" Minimum="0" Maximum="200" Value="{Binding ImageX, Mode=TwoWay}" />
            <Slider x:Name="sImageVertPos" Grid.Row="1" Grid.Column="1" Orientation="Vertical" Minimum="0" Maximum="100" Value="{Binding ImageY, Mode=TwoWay}" />
            <Canvas Grid.Row="1" x:Name="cStructureImage" Margin="30" MouseMove="cStructureImage_MouseMove">
                <Image Source="{Binding Image.Bitmap}" Stretch="None" />
                <Canvas.RenderTransform>
                    <TransformGroup>
                        <ScaleTransform ScaleX="{Binding ElementName=sImageScale, Path=Value}"
                                    ScaleY="{Binding ElementName=sImageScale, Path=Value}"
                         />

                        <TranslateTransform X="{Binding ImageX}" Y="{Binding ImageY}"
                         />
                    </TransformGroup>
                </Canvas.RenderTransform>
            </Canvas>
            <Slider x:Name="sImageScale" Grid.Row="2" Minimum="1" Maximum="3" Value="2" />
        </Grid>
        <ScrollViewer Grid.Column="3" Grid.RowSpan="2">
            <local:ShapeView x:Name="svShape" Margin="2,0,2,0" IsHighDefenition="{Binding IsHighDefenition}" />
        </ScrollViewer>
        <local:ShapeView3D x:Name="svShape3D" Grid.Row="1" Grid.ColumnSpan="3" />
    </Grid>
</UserControl>
